package com.ljh.blog.controller;

import com.ljh.blog.pojo.dataobject.BlogInfo;
import com.ljh.blog.pojo.request.AddBlogRequest;
import com.ljh.blog.pojo.request.UpdateBlogRequest;
import com.ljh.blog.pojo.response.BlogInfoResponse;
import com.ljh.blog.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Themberfue
 * @date: 2025/3/30 20:50
 * @description:
 */
@Slf4j
@RequestMapping("/blog")
@RestController
public class BlogController {
    @Resource(name = "blogServiceImpl")
    BlogService blogService;

    @GetMapping("/getList")
    public List<BlogInfoResponse> getList() {
        log.info("获取博客...");
        return blogService.getList();
    }

    @GetMapping("/getBlogDetails")
    public BlogInfoResponse getBlogDetails(@NotNull Integer blogId) {
        log.info("获取详细博客...");
        return blogService.getBlogDetails(blogId);
    }

    @PostMapping("/postBlog")
    public Boolean postBlog(@RequestBody @Validated AddBlogRequest blog) {
        log.info("发布博客...");
        return blogService.postBlog(blog);
    }

    @PutMapping("/updateBlog")
    public Boolean updateBlog(@RequestBody @Validated UpdateBlogRequest updateBlogRequest) {
        log.info("更新博客...");
        return blogService.updateBlog(updateBlogRequest);
    }

    @DeleteMapping("/deleteBlog")
    public Boolean deleteBlog(@NotNull Integer blogId) {
        log.info("删除博客...");
        return blogService.deleteBlog(blogId);
    }
}
